package com.eedi.framework.mail.dal.mapper;

import com.eedi.framework.common.pojo.PageResult;
import com.eedi.framework.mybatis.core.mapper.BaseMapperX;
import com.eedi.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.eedi.framework.mail.controller.sys.vo.template.MailTemplatePageReq;
import com.eedi.framework.mail.dal.dataobject.SysMailTemplateDO;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface SysMailTemplateMapper extends BaseMapperX<SysMailTemplateDO> {

    default PageResult<SysMailTemplateDO> selectPage(MailTemplatePageReq pageReqVO){
        return selectPage(pageReqVO , new LambdaQueryWrapperX<SysMailTemplateDO>()
                .eqIfPresent(SysMailTemplateDO::getStatus, pageReqVO.getStatus())
                .likeIfPresent(SysMailTemplateDO::getCode, pageReqVO.getCode())
                .likeIfPresent(SysMailTemplateDO::getName, pageReqVO.getName())
                .eqIfPresent(SysMailTemplateDO::getSysMailAccountId, pageReqVO.getAccountId())
                .betweenIfPresent(SysMailTemplateDO::getCreateTime, pageReqVO.getCreateTime()));
    }

    default Long selectCountByAccountId(String accountId) {
        return selectCount(SysMailTemplateDO::getSysMailAccountId, accountId);
    }

    default SysMailTemplateDO selectByCode(String code) {
        return selectOne(SysMailTemplateDO::getCode, code);
    }

}
